import host from "@/config/index.js";
import http from "@/utils/http";

// 原有邮箱/密码登录相关接口（保持不变）
export const sendEmail = (params) => {
  return http({
    url: `${host.BASE_API}/user/v1/sendEmail`,
    method: "POST",
    data: params,
  });
};

export const checkEmail = params => {
  return http({
    url: `${host.BASE_API}/user/v1/checkEmail`,
    method: "POST",
    data: params,
  });
};

export const resetPass = params => {
  return http({
    url: `${host.BASE_API}/user/v1/resetPass`,
    method: "POST",
    data: params,
  });
};

export const toReg = (params) => {
  return http({
    url: `${host.BASE_API}/user/v1/register`,
    method: "POST",
    data: params,
  });
};

export const toLogin = (params) => {
  return http({
    url: `${host.BASE_API}/user/v1/login`,
    method: "POST",
    data: params,
  });
};

// 1. 微信内OAuth授权接口（仅微信内使用）
export const wxauth = () => {
  return http({
    url: `${host.BASE_API}/wechat/v1/auth`, // 后端OAuth授权接口（微信内专用）
    method: "GET",
    params: {},
  });
};

export const wxauthCallback = (params) => {
  return http({
    url: `${host.BASE_API}/wechat/v1/callback`, // 后端OAuth回调接口
    method: "GET",
    params,
  });
};

// 2. PC端扫码登录接口（仅PC端使用，新增独立接口，避免与OAuth混淆）
export const getScanQrCode = (params) => {
  return http({
    url: `${host.BASE_API}/wechat/v1/loginQrCode`, // 后端扫码二维码接口（PC专用）
    method: "GET",
    params, // 传clientIp、fp
  });
};

export const getScanStatus = (params) => {
  return http({
    url: `${host.BASE_API}/wechat/v1/scanStatus`, // 后端扫码状态接口
    method: "GET",
    params, // 传scanId
  });
};

// IP获取接口（保持不变）
export const getPublicIp = () => {
  return http({
    url: "http://pv.sohu.com/cityjson?ie=utf-8",
    method: "get",
    withCredentials: false,
    headers: {
      Origin: false,
      Referer: false,
    },
  });
};

export let getIp = () => {
  return http({
    url: `https://qifu-api.baidubce.com/ip/local/geo/v1/district`,
    method: "get",
    withCredentials: false,
    headers: {
      Origin: false,
      Referer: false,
    },
  });
};